1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"1038.29">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000ca0; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #ac0d06}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #4d4d4d}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000db0}
20 span
.s1
{color: #0012f3}
21 span
.s2
{color: #0012fd}
22 span
.s3
{color: #000000}
23 span
.s4
{color: #000db0}
24 span
.s5
{color: #4d4d4d}
25 span
.s6
{color: #ac0d06}
26 span
.s7
{color: #176208}
27 span
.Apple-tab-span
{white-space:pre
}
31 <p class=
"p1"><b>DiskIn
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>stream in audio from a file
</b></p>
33 <p class=
"p2"><br></p>
34 <p class=
"p3"><b>DiskIn.ar(numChannels, bufnum, loop )
</b></p>
35 <p class=
"p2"><br></p>
36 <p class=
"p3">Continuously play a longer soundfile from disk.
<span class=
"Apple-converted-space"> </span>This requires a buffer to be preloaded with one buffer size of sound. If loop is set to
1, the soundfile will loop.
</p>
37 <p class=
"p4"><br></p>
38 <p class=
"p3"><b>See also:
</b> <a href=
"PlayBuf.html"><span class=
"s1">PlayBuf
</span></a>,
<a href=
"../Oscillators/BufRd.html"><span class=
"s2">BufRd
</span></a><span class=
"Apple-converted-space"> </span></p>
39 <p class=
"p5"><br></p>
40 <p class=
"p6"><span class=
"s3">s.boot;
</span>// start the server
</p>
41 <p class=
"p5"><br></p>
43 <p class=
"p7"><span class=
"s4">SynthDef
</span>(
<span class=
"s5">"help-Diskin"</span>, {
<span class=
"s4">arg
</span> bufnum =
0;
</p>
44 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s4">Out
</span>.ar(
0,
<span class=
"s4">DiskIn
</span>.ar(
1, bufnum,
1));
</p>
45 <p class=
"p7">}).add
</p>
47 <p class=
"p5"><br></p>
48 <p class=
"p8"><b>Using Buffer (Object Style)
</b></p>
49 <p class=
"p5"><br></p>
50 <p class=
"p7">b =
<span class=
"s4">Buffer
</span>.cueSoundFile(s,
<span class=
"s5">"sounds/a11wlk01-44_1.aiff"</span>,
0,
1);
</p>
51 <p class=
"p5"><br></p>
52 <p class=
"p7">x = {
<span class=
"s4">DiskIn
</span>.ar(
1, b) }.play;
</p>
53 <p class=
"p5"><br></p>
54 <p class=
"p7">b.close;
<span class=
"Apple-tab-span"> </span></p>
55 <p class=
"p5"><br></p>
56 <p class=
"p6">// again
</p>
57 <p class=
"p6">// note the like named instance method, but different arguments
</p>
58 <p class=
"p9"><span class=
"s3">b.cueSoundFile(
</span>"sounds/a11wlk01-44_1.aiff"<span class=
"s3">,
0);
<span class=
"Apple-tab-span"> </span></span></p>
59 <p class=
"p5"><span class=
"Apple-tab-span"> </span></p>
60 <p class=
"p7">x.free; b.close; b.free;
<span class=
"Apple-tab-span"> </span></p>
61 <p class=
"p5"><br></p>
62 <p class=
"p5"><br></p>
63 <p class=
"p5"><br></p>
64 <p class=
"p6">// loop it (for better looping use PlayBuf!)
</p>
66 <p class=
"p9"><span class=
"s3">p =
</span>"sounds/a11wlk01-44_1.aiff"<span class=
"s3">;
</span></p>
67 <p class=
"p7">a =
<span class=
"s4">SoundFile
</span>.new;
</p>
68 <p class=
"p7">a.openRead(p);
</p>
69 <p class=
"p7">d = a.numFrames/s.sampleRate;
<span class=
"s6">// get the duration
</span></p>
70 <p class=
"p6"><span class=
"s3">a.close;
</span>// don't forget
</p>
71 <p class=
"p7">b =
<span class=
"s4">Buffer
</span>.cueSoundFile(s, p,
0,
1);
</p>
72 <p class=
"p7">f = {
<span class=
"s4">DiskIn
</span>.ar(
1, b) };
</p>
73 <p class=
"p7">x = f.play;
</p>
74 <p class=
"p10"><span class=
"s3">r =
</span>Routine
<span class=
"s3">({
</span></p>
75 <p class=
"p7"><span class=
"Apple-tab-span"> </span>loop({ d.wait; x.free; x = f.play; b.close( b.cueSoundFileMsg(p,
0)) });
</p>
76 <p class=
"p7">}).play;
</p>
78 <p class=
"p6"><span class=
"s3">r.stop; x.free; b.close; b.free;
</span>// you need to do all these to properly cleanup
</p>
79 <p class=
"p5"><br></p>
80 <p class=
"p5"><br></p>
81 <p class=
"p5"><br></p>
82 <p class=
"p6">// cue and play right away
</p>
84 <p class=
"p7"><span class=
"s4">SynthDef
</span>(
<span class=
"s5">"help-Diskin"</span>, {
<span class=
"s4">arg
</span> bufnum =
0;
</p>
85 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"s4">Out
</span>.ar(
0,
<span class=
"s4">DiskIn
</span>.ar(
1, bufnum));
</p>
86 <p class=
"p7">}).add;
</p>
88 <p class=
"p7">(
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
89 <p class=
"p7">x =
<span class=
"s4">Synth
</span>.basicNew(
<span class=
"s5">"help-Diskin"</span>);
</p>
90 <p class=
"p7">m = {
<span class=
"s4">arg
</span> buf; x.addToHeadMsg(
<span class=
"s4">nil
</span>, [
<span class=
"s7">\bufnum
</span>, buf])};
</p>
91 <p class=
"p5"><br></p>
92 <p class=
"p7">b =
<span class=
"s4">Buffer
</span>.cueSoundFile(s,
<span class=
"s5">"sounds/a11wlk01-44_1.aiff"</span>,
0,
1, completionMessage: m);
</p>
93 <p class=
"p7">)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
94 <p class=
"p5"><br></p>
95 <p class=
"p7">x.free; b.close; b.free;
<span class=
"Apple-tab-span"> </span><span class=
"s6">//clean up
</span></p>
96 <p class=
"p5"><br></p>
97 <p class=
"p5"><br></p>
98 <p class=
"p5"><br></p>
99 <p class=
"p8"><b>OSC Messaging Style
</b></p>
100 <p class=
"p5"><br></p>
101 <p class=
"p6">// allocate a disk i/o buffer
</p>
102 <p class=
"p7">s.sendMsg(
<span class=
"s5">"/b_alloc"</span>,
0,
65536,
1);
</p>
103 <p class=
"p5"><br></p>
104 <p class=
"p6">// open an input file for this buffer, leave it open
</p>
105 <p class=
"p9"><span class=
"s3">s.sendMsg(
</span>"/b_read"<span class=
"s3">,
0,
</span>"sounds/a11wlk01-44_1.aiff"<span class=
"s3">,
0,
65536,
0,
1);
</span></p>
106 <p class=
"p5"><br></p>
107 <p class=
"p6">// create a diskin node
</p>
108 <p class=
"p7">s.sendMsg(
<span class=
"s5">"/s_new"</span>,
<span class=
"s5">"help-Diskin"</span>, x = s.nextNodeID,
1,
1);
</p>
109 <p class=
"p5"><br></p>
110 <p class=
"p6"><span class=
"s3">s.sendMsg(
</span><span class=
"s5">"/b_close"</span><span class=
"s3">,
0);
</span>// close the file (very important!)
</p>
111 <p class=
"p5"><br></p>
112 <p class=
"p5"><br></p>
113 <p class=
"p6">// again
<span class=
"Apple-converted-space"> </span></p>
114 <p class=
"p6">// don't need to reallocate and Synth is still reading
</p>
115 <p class=
"p9"><span class=
"s3">s.sendMsg(
</span>"/b_read"<span class=
"s3">,
0,
</span>"sounds/a11wlk01-44_1.aiff"<span class=
"s3">,
0,
0,
0,
1);
</span></p>
116 <p class=
"p5"><br></p>
117 <p class=
"p7">s.sendMsg(
<span class=
"s5">"/n_free"</span>, x);
<span class=
"s6">// stop reading
</span></p>
118 <p class=
"p5"><br></p>
119 <p class=
"p6"><span class=
"s3">s.sendMsg(
</span><span class=
"s5">"/b_close"</span><span class=
"s3">,
0);
</span>// close the file.
</p>
120 <p class=
"p5"><br></p>
121 <p class=
"p6"><span class=
"s3">s.sendMsg(
</span><span class=
"s5">"/b_free"</span><span class=
"s3">,
0);
</span>// frees the buffer
</p>
122 <p class=
"p5"><br></p>